import 'package:flustars/flustars.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:wechat_kit/wechat_kit_platform_interface.dart';
import 'package:tracker/common/enums/user_type_enum.dart';
import 'package:tracker/common/log/x_logger.dart';
import 'package:tracker/common/pay/wxpay_utils.dart';
import 'package:tracker/provider/global_provider.dart';
import 'package:tracker/router/router_manager.dart';
import 'package:tracker/theme/app_theme.dart';
import 'package:tracker/utils/toast_utils.dart';

class EmptyDeviceWidget extends ConsumerStatefulWidget {
  const EmptyDeviceWidget({super.key});

  @override
  ConsumerState<EmptyDeviceWidget> createState() => _EmptyDeviceWidgetState();
}

class _EmptyDeviceWidgetState extends ConsumerState<EmptyDeviceWidget> {
  _buildBindDeviceBtn() {
    final userType = ref.watch(userTypeProvider);
    XLogger.debug('userType: $userType');
    if (userType == UserTypeEnum.phone || userType == UserTypeEnum.device) {
      return ElevatedButton(
        onPressed: () {
          // 只有手机号登录的用户才能添加设备，设备登录的用户不可以添加设备
          if (userType == UserTypeEnum.phone) {
            context.push(RouterManager.bindDevice);
          } else {
            ToastUtils.showToast('绑定多台设备请使用手机号登录');
          }
        },
        style: ElevatedButton.styleFrom(
          backgroundColor: AppTheme.themeConfig.primaryColor,
          foregroundColor: Colors.white,
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(20),
          ),
        ),
        child: const Text('添加设备'),
      );
    }
    return const SizedBox();
  }

  @override
  Widget build(BuildContext context) {
    return SingleChildScrollView(
      child: SizedBox(
        height: ScreenUtil.getScreenH(context) - 200,
        child: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              // 图片
              Image.asset(
                'assets/images/error/state_empty@3x.png',
                width: ScreenUtil.getScreenW(context) * 0.8,
              ),
              const SizedBox(height: 20),
              _buildBindDeviceBtn()
            ],
          ),
        ),
      ),
    );
  }
}
